package logic

import (
	"context"
	"furni-set/models/mysql"

	"furni-set/funrpc/funrpc"
	"furni-set/funrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FruitShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFruitShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FruitShowLogic {
	return &FruitShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FruitShowLogic) FruitShow(in *funrpc.FruitShowRequest) (*funrpc.FruitShowResponse, error) {
	// todo: add your logic here and delete this line
	var fruit mysql.Fruit
	if err := fruit.ShowFruit(mysql.DB, in.FruitsId); err != nil {
		return nil, err
	}
	var brand mysql.Brand
	var sort mysql.Sort
	return &funrpc.FruitShowResponse{
		FruitsId:   int64(fruit.ID),
		FruitName:  fruit.FruitName,
		FruitPrice: float32(fruit.FruitPrice),
		FruitNum:   fruit.FruitNum,
		BrandName:  brand.BrandName,
		SortName:   sort.SortName,
	}, nil
}
